package com.beidouapp.dao;

import java.util.List;

import com.beidouapp.domain.pojo.Dict;
import com.beidouapp.domain.pojo.DictType;
import com.beidouapp.exception.BusinessException;

/**
 * Base code dictionary manager.
 */
public interface DictDao
{
    /**
     * Add a base code dictionary item.
     * 
     * @param dict the dictionary item.
     * @return the dictionary item after it was saved.
     * @exception throw out when dictCode join dictTypeCode was exists.
     */
    public Dict addDict (Dict dict) throws BusinessException;

    /**
     * Modify a dictionary item.
     * 
     * @param dict the dictionary item.
     * @exception throw out when dictCode join dictTypeCode was exists.
     */
    public void modifyDict (Dict dict) throws BusinessException;

    /**
     * Remove a dictionary item.
     * 
     * @param dict the dictionary item.
     * @exception throw out when the dictionary item has children.
     */
    public void removeDict (Integer dictItemId) throws BusinessException;

    /**
     * Look up a dictionary item under its fully qualified name and type code.
     * 
     * @param itemCodeFqn item fully qualified name composed of parent's
     *            dictionary code and itself's dictionary code, it's join with
     *            ".".
     * @param dictTypeCode dictionary type code.
     * @return a dictionary item.
     */
    public Dict getDict (String itemCodeFqn, String dictTypeCode);

    /**
     * get dictionary item by dictItemId.
     * 
     * @param dictId dictItemId.
     * @return a dictionary item.
     */
    public Dict getDictById (Integer dictItemId);

    /**
     * Look up a dictionary item's children items under its fully qualified name
     * and type code. Fqn = "/" means look up root dictionary items
     * 
     * @param itemCodeFqn item fully qualified name composed of parent's
     *            dictionary code and itself's dictionary code, it's join with
     *            ".".
     * @param dictTypeCode dictionary type code.
     * @return the children items.
     */
    public List <Dict> findChildrenDict (String itemCodeFqn, String dictTypeCode);
    
    /**
     * Look up all dictionary items which dictionary type code = dictTypeCode
     * 
     * @param dictTypeCode dictionary type code.
     * @return the dictionary items.
     */
    public List<Dict> findDictByDictTypeCode (String dictTypeCode);

    /**
     * Add a dictionary type.
     * 
     * @param dictType the dictionary type.
     * @exception throw out when the type code is exist.
     */
    public void addDictType (DictType dictType) throws BusinessException;

    /**
     * Modify the dictionary type.
     * 
     * @param dictType the dictionary type.
     */
    public void modifyDictType (DictType dictType);

    /**
     * Remove a dictionary type by dictTypeCode
     * 
     * @param dictTypeCode dictionary type code
     * @exception throw out when the type was referenced by dictionary item.
     */
    public void removeDictType (String dictTypeCode) throws BusinessException;

    /**
     * Look up a dictionary type under dictTypeCode.
     * 
     * @param dictTypeCode dictionary type code.
     * @return the dictionary type.
     */
    public DictType getDictType (String dictTypeCode);

    /**
     * find all dictionary type.
     * 
     * @return dictionary types collection
     */
    public List <DictType> findAllDictType ();

    /**
     * find all dictionary.
     * 
     * @param isExceptingNotLoadOnStart if true, just load the dictionary which
     *            dictionary's property loadOnStart = 1, other wise to load all
     *            dictionary.
     * @return dictionary collection.
     */
    public List <Dict> findAllDict (boolean isExceptingNotLoadOnStart);
}
